package com.etl.dataflow.executor.element;

import java.nio.charset.Charset;
import java.sql.Date;
import java.sql.Timestamp;

/**
 * @author dx
 * @since 2022/4/14
 */
public abstract class Column<T> {

    protected String name;
    protected T value;
    protected int jdbcType;
    protected String jdbcTypeName;
    protected Charset charset;

    protected Column(String name, T value, int jdbcType, String jdbcTypeName) {
        this(name, value, jdbcType, jdbcTypeName, null);
    }

    protected Column(String name, T value, int jdbcType, String jdbcTypeName, Charset charset) {
        this.name = name;
        this.value = value;
        this.jdbcType = jdbcType;
        this.jdbcTypeName = jdbcTypeName;
        this.charset = charset;
    }

    public abstract String asString();

    public abstract byte[] asBytes();

    public abstract Timestamp asTimestamp();

    public abstract Date asDate();

    public abstract int getByteSize();

    public T getValue() {
        return this.value;
    }

    public void setValue(T value) {
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Charset getCharset() {
        return charset;
    }

    public void setCharset(Charset charset) {
        this.charset = charset;
    }

    public int getJdbcType() {
        return jdbcType;
    }

    public void setJdbcType(int jdbcType) {
        this.jdbcType = jdbcType;
    }

    public String getJdbcTypeName() {
        return jdbcTypeName;
    }

    public void setJdbcTypeName(String jdbcTypeName) {
        this.jdbcTypeName = jdbcTypeName;
    }

    @Override
    public String toString() {
        return "Column{" +
                "name='" + name + '\'' +
                ", value=" + value +
                ", jdbcType=" + jdbcType +
                ", jdbcTypeName='" + jdbcTypeName + '\'' +
                ", charset=" + charset +
                '}';
    }
}
